import { redirect } from "next/navigation";

import { DashboardView } from "@/components/dashboard/dashboard-view";
import { getAuthenticatedUser, getProjectSummaries } from "@/lib/server-data";

export default async function DashboardPage() {
  const user = await getAuthenticatedUser();

  if (!user) {
    redirect("/auth/login");
  }

  const projects = await getProjectSummaries();

  return (
    <section className="mx-auto flex w-full max-w-5xl flex-col gap-6 px-6 py-12">
      <div className="flex flex-col gap-4">
        <h1 className="text-2xl font-semibold">仪表盘</h1>
        <p className="text-sm text-muted-foreground">
          查看个人信息、项目产值概览与排产进度。后续迭代将补充日报统计和异常提醒。
        </p>
      </div>
      <DashboardView initialUser={user} initialProjects={projects} />
    </section>
  );
}
